#
# Copyright (C) [2024] Xingyun Integrated Circuit, Inc.
#
#   GreenCode was a private technology asset of Xingyun Integrated Circuit， Inc （Confidential）
#   Author :  Shawn.Tan
#   Date : 2025.10.28
#
#   History : Initial Version 2025.10.28
#
#
from base.exception_handlers.ReusableSequence import ReusableSequence
from gpgpu.exception_handlers.ExceptionHandlerContext import RegisterCallRole


class SkipInstructionHandlerGPGPU(ReusableSequence):
    def generateHandler(self, **kwargs):
        try:
            handler_context = kwargs["handler_context"]
        except KeyError:
            self.error(
                "INTERNAL ERROR: one or more arguments to "
                "SkipInstructionHandlerGPGPU generate method missing."
            )

        self.debug(
            "[SkipInstructionHandlerGPGPU] generate handler address: 0x%x" % self.getPEstate("PC")
        )

        priv_level_reg_index = handler_context.getScratchRegisterIndices(
            RegisterCallRole.PRIV_LEVEL_VALUE
        )
        scratch_reg_index = handler_context.getScratchRegisterIndices(
            RegisterCallRole.TEMPORARY, 1
        )

        self.mAssemblyHelper.genIncrementExceptionReturnAddress(
            scratch_reg_index, priv_level_reg_index
        )
        self.mAssemblyHelper.genReturn()
